/*
 * cudanDynamicGlobalMemory.h
 *
 *  Created on: Jan 8, 2010
 *      Author: daniel
 */

#ifndef CUDANDYNAMICGLOBALMEMORY_H_
#define CUDANDYNAMICGLOBALMEMORY_H_

#include "cudanDeviceMemory.h"

namespace CUDAN
{
	// Defines an implementation for dynamic memory on the device.
	template<typename T>
	class DynamicGlobalMemory
	{
	public:
		// Pre-allocated buffer of global memory available for threads.
		GlobalMemory<T,2> buffer;

		// Stores the next available position in memory available to a thread.
		int* currentIndex;

		// Number of threads with space allocated.
		int numthreads;

		// Number of dynamic allocations available to each thread.
		int size;

	public:
		DynamicGlobalMemory();
		DynamicGlobalMemory(int,int);

	public:
		void setBufferSize(int,int);
		void resetIndex();
		__device__ T* create(int,int);
	};
}

#include "cudanDynamicGlobalMemory.cpp"

#endif /* CUDAFWDYNAMICGLOBALMEMORY_H_ */
